﻿using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParkingLot.Utility.ConcurrentCollection
{
    /// <summary>
    /// 同步字典仓库
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    /// <typeparam name="TValue"></typeparam>
    public class ConDictionaryStore<TKey, TValue>
    {
        #region 字段

        private ConcurrentDictionary<TKey, TValue>[] arreyDictionaries=new ConcurrentDictionary<TKey, TValue>[2];

        /// <summary>
        /// 默认数量
        /// </summary>
        private int DefultCount;

        /// <summary>
        /// 当前集合
        /// </summary>
        private int currentIndex = 0;
        #endregion

        #region 构造

        /// <summary>
        ///   集合
        /// </summary>
        /// <param name="concurrencyLevel"> 将同时更新 System.Collections.Concurrent.ConcurrentDictionary`2 的线程的估计数量。</param>
        /// <param name="capacity"> System.Collections.Concurrent.ConcurrentDictionary`2 可包含的初始元素数。</param>
        public ConDictionaryStore(int concurrencyLevel, int capacity)
        {
            ConcurrentDictionary<TKey, TValue> m_DictFirst = new ConcurrentDictionary<TKey, TValue>(concurrencyLevel, capacity);

            ConcurrentDictionary<TKey, TValue> m_DictSencond = new ConcurrentDictionary<TKey, TValue>(concurrencyLevel, capacity);

            arreyDictionaries[0] = m_DictFirst;

            arreyDictionaries[1] = m_DictSencond;
            DefultCount = capacity;
        }

        public ConDictionaryStore()
        {
            ConcurrentDictionary<TKey, TValue> m_DictFirst = new ConcurrentDictionary<TKey, TValue>();

            ConcurrentDictionary<TKey, TValue> m_DictSencond = new ConcurrentDictionary<TKey, TValue>();

            arreyDictionaries[0] = m_DictFirst;

            arreyDictionaries[1] = m_DictSencond;
        }
        #endregion

        #region 方法

        public bool TryAdd(TKey key, TValue value)
        {
            if (arreyDictionaries[0].Count < DefultCount && arreyDictionaries[1].Count < DefultCount)
            {
                if (arreyDictionaries[0].TryAdd(key, value))
                {
                    return true;
                }
                return false;
            }
            else if(arreyDictionaries[0].Count== DefultCount)
            {
                
            }


            
            return false;
        }

        public void Clear()
        {
            
        }
        #endregion
    }
}
